package cn.maxwell._01_deye;

import org.apache.rocketmq.client.producer.DefaultMQProducer;
import org.apache.rocketmq.client.producer.SendResult;
import org.apache.rocketmq.common.message.Message;

import java.nio.charset.StandardCharsets;
import java.text.SimpleDateFormat;

public class Producer {
    public static void main(String[] args) throws Exception {
        //1.创建消费者对象
        DefaultMQProducer Producer = new DefaultMQProducer("deye-producer-group");
        //2.设置namesrv地址
        Producer.setNamesrvAddr("localhost:9876");
        //3.启动Producer实例
        Producer.start();
        //4.设置消息
        Message message = new Message("deye", "hello", "这是一条延时消息！".getBytes(StandardCharsets.UTF_8));
        //设置延时等级：4级=30s
        //messageDelayLevel=1s 5s 10s 30s 1m 2m 3m 4m 5m 6m 7m 8m 9m 10m 20m 30m 1h 2h
        message.setDelayTimeLevel(4);
        //5.发送消息
        SendResult send = Producer.send(message);
        System.out.println(send);
        System.out.println(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(System.currentTimeMillis()));
        //6.关闭
        Producer.shutdown();
    }
}
